package com.baibei.widget.dialog;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.InsetDrawable;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.view.Window;

import com.baibei.widget.R;
import com.rae.widget.dialog.impl.AppDialog;

/**
 * 弹出窗口基类
 * Created by ChenRui on 2017/6/6 0006 13:43.
 */
public abstract class BaibeiDialog extends AppDialog {

    public BaibeiDialog(Context context) {
        super(context, R.style.Widget_Dialog);
    }


    @Override
    protected void initDialog() {
        if (getWindow() != null) {
            getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        }
        setContentView(getLayoutId());
        onCreatedView();
        super.initDialog();
        if (getWindow() != null) {
            onCreateWindow(getWindow());
        }
    }

    protected void onCreateWindow(Window window) {
        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getContext().getResources().getDisplayMetrics());
        InsetDrawable drawable = new InsetDrawable(new ColorDrawable(Color.WHITE), margin, 0, margin, 0);
        window.setBackgroundDrawable(drawable);
        window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
        window.getAttributes().height = ViewGroup.LayoutParams.WRAP_CONTENT;

    }

    public abstract int getLayoutId();

    protected abstract void onCreatedView();
}
